package recharge_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeTypeListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 充值类型--列表
func NewRechargeTypeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeTypeListLogic {
	return &RechargeTypeListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeTypeListLogic) RechargeTypeList(req *types.RechargeTypeListRequest) (resp *types.RechargeTypeListResponse, err error) {
	var commonResp types.CommonResp

	in := rpc.RechargeTypeListRequest{Name: req.Name}
	rpcResp, err := l.svcCtx.AssetsRpc.PayRecharge.AdminRechargeTypeList(l.ctx, &in)
	if err != nil {
		return nil, err
	}
	var records []types.RechargeTypeList

	for _, t := range rpcResp.Records {
		records = append(records, types.RechargeTypeList{
			Id:             t.Id,
			CreatedAt:      t.CreatedAt,
			UpdatedAt:      t.UpdatedAt,
			DeletedAt:      t.DeletedAt,
			RechargeId:     t.RechargeId,
			SelectedIcon:   t.SelectedIcon,
			UnselectedIcon: t.UnselectedIcon,
			Name:           t.Name,
			InternalName:   t.InternalName,
			Status:         t.Status,
			Sort:           t.Sort,
		})
	}

	return &types.RechargeTypeListResponse{
		Records:    records,
		CommonResp: commonResp,
	}, nil
}
